home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
PIL
/
ImageStat.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
4KB
|
150 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
import Image
import operator
import math
class Stat:
def __init__(self, image_or_list, mask = None):
try:
if mask:
self.h = image_or_list.histogram(mask)
else:
self.h = image_or_list.histogram()
except AttributeError:
self.h = image_or_list
if type(self.h) != type([]):
raise TypeError, 'first argument must be image or list'
self.bands = range(len(self.h) / 256)
def __getattr__(self, id):
if id[:4] == '_get':
raise AttributeError, id
v = getattr(self, '_get' + id)()
setattr(self, id, v)
return v
def _getextrema(self):
def minmax(histogram):
n = 255
x = 0
for i in range(256):
if histogram[i]:
n = min(n, i)
x = max(x, i)
continue
return (n, x)
v = []
for i in range(0, len(self.h), 256):
v.append(minmax(self.h[i:]))
return v
def _getcount(self):
v = []
for i in range(0, len(self.h), 256):
v.append(reduce(operator.add, self.h[i:i + 256]))
return v
def _getsum(self):
v = []
for i in range(0, len(self.h), 256):
sum = 0
for j in range(256):
sum = sum + j * self.h[i + j]
v.append(sum)
return v
def _getsum2(self):
v = []
for i in range(0, len(self.h), 256):
sum2 = 0
for j in range(256):
sum2 = sum2 + j ** 2 * float(self.h[i + j])
v.append(sum2)
return v
def _getmean(self):
v = []
for i in self.bands:
v.append(self.sum[i] / self.count[i])
return v
def _getmedian(self):
v = []
for i in self.bands:
s = 0
l = self.count[i] / 2
b = i * 256
for j in range(256):
s = s + self.h[b + j]
if s > l:
break
continue
v.append(j)
return v
def _getrms(self):
v = []
for i in self.bands:
v.append(math.sqrt(self.sum2[i] / self.count[i]))
return v
def _getvar(self):
v = []
for i in self.bands:
n = self.count[i]
v.append((self.sum2[i] - self.sum[i] ** 2 / n) / n)
return v
def _getstddev(self):
v = []
for i in self.bands:
v.append(math.sqrt(self.var[i]))
return v
Global = Stat
if __name__ == '__main__':
im = Image.open('Images/lena.ppm')
st = Stat(im)
print 'extrema', st.extrema
print 'sum ', st.sum
print 'mean ', st.mean
print 'median ', st.median
print 'rms ', st.rms
print 'sum2 ', st.sum2
print 'var ', st.var
print 'stddev ', st.stddev